var dynamicAttacherObj;
var timer;
var animating;
var canvas;
var waves;

function Animate( ) {
	if(animating) {
		waves.Animate( );
	}
}

function onInit( ) {
	animating = false;
	dynamicAttacherObj = document.getElementById('DynamicAttacher');
	waves = new Waves( );
	waves.Add(new Wave(Math.sin, 10, .10, 0), new ColorConvert(DotNetTypeColors.MidnightBlue).Rgb( ), 100);
	waves.Add(new Wave(Math.sin, 20, .10, 10), new ColorConvert(DotNetTypeColors.DarkOrchid).Rgb( ), 100);
	waves.Add(new Wave(Math.sin, 40, .10, 20), new ColorConvert(DotNetTypeColors.Firebrick).Rgb( ), 100);
	waves.Add(new Wave(Math.sin, 80, .10, 30), new ColorConvert(DotNetTypeColors.CornflowerBlue).Rgb( ), 100);
	waves.Add(new Wave(Math.sin, 100, .10, 30), new ColorConvert(DotNetTypeColors.CornflowerBlue).Rgb( ), 100);

	var graphics = new Graphics('Physics');
	try {
		canvas = graphics.CreateCanvas(400, 200, 'Canvas');
		canvas.PlotPixel(2, 2, Color.Black, 50, null);
		canvas.SetLocation(50, 50);
		canvas.CreateBorder('1px', 'solid', Color.Black);
		graphics.Attach(dynamicAttacherObj, canvas);
		
		graphics.Attach(dynamicAttacherObj, graphics.drawRect(460, 50, 600, 90, new ColorConvert(DotNetTypeColors.SeaGreen).Rgb( ), Border.Solid, new ColorConvert(DotNetTypeColors.Black).Rgb( ), 20, 'toggler', 'Toggle Animation'));


		timer = setInterval(Animate, 1);
	}
	catch(ex) {
		// dump(ex);
		throw ex;
	}

	document.getElementById('toggler').oncontextmenu = function(evt) {
		waves.ResetAll( );
		graphics.CleanCanvas(canvas);
		return false;
	}

	document.getElementById('toggler').onclick = function(evt) {
		if(animating) {
			animating = false;
		}
		else {
			animating = true;
		}
	}
}

if(window.addEventListener) {
	window.addEventListener('load', function(evt) {
		onInit( );
	}, false);
}
else if(window.attachEvent) {
	window.attachEvent('onload', function(evt) {
		onInit( );
	});
}